package com.goro;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.model.SelectItem;

import com.joro.Customer;
import com.joro.ejb.CustomerFacadeLocal;
public class CustomerBean {
	
	@EJB
	protected CustomerFacadeLocal customerDao;
	private Customer customer;
	
	
	public CustomerBean() {
		customer = new Customer();
	}
	
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Collection<Customer> getCustomers(){
		return customerDao.getCustomers();
	}
	
	public Collection<String> getCustomersAsString() {
		List<String> res = new ArrayList<String>();
		Collection<Customer> customers = customerDao.getCustomers();
		for (Customer customer : customers) {
			res.add(customer.getName());
		}
		return res;
	}
	
	public Collection<SelectItem> getCustomerItems() {
		List<SelectItem> res = new ArrayList<SelectItem>();
		Collection<Customer> customers = customerDao.getCustomers();
		for (Customer customer : customers) {
			SelectItem item = new SelectItem();
			item.setLabel(customer.getName());
			item.setValue(customer.getId());
			res.add(item);
		}
		return res;
	}
	
	
	public String deleteCustomer() {
		customerDao.deleteCustomer(customer);		
		return null;
	}
}
